home *** CD-ROM | disk | FTP | other *** search
/ El Mac 1 / Magazine.iso / EL MAC 1 / Shareware / HyperCard / XCMD Docs / CompileIt! Source Code / CompileItDraw < prev    next >
Encoding:
Text File  |  1995-08-20  |  8.6 KB  |  239 lines  |  [TEXT/ttxt]

  1. global TempRect:R[8],colorBlack:R,ColorBorder:R,CommandKeyWasOrIsDown:B
  2. global Color:R[6]
  3. global tool1:I
  4. Global MyEventRecord:R,TheMouseLoc:L,TheTicks:L,TheMsg:L,TheModifiers:I
  5. on CompileItDraw
  6.   hide menubar
  7.   put false into CommandKeyWasOrIsDown
  8.   put MakeWindow("Draw",0,0,512,342,0) into MyWind
  9.   setPort myWind
  10.   DrawButton
  11.   repeat until CommandKeyWasOrIsDown
  12.     get HandleEvent()
  13.   end repeat
  14.   DisposeWindow MyWind
  15.   show menubar
  16. end CompileItDraw
  17.  
  18. ------------LIBRARY ROUTINES-----------------
  19. function HandleButton clickH,clickV
  20.   return GetBtn(ClickH,ClickV)
  21. end HandleButton
  22.  
  23. function MakeWindow WindowName,rect1,rect2,rect3,rect4,procId
  24.   -- to dispose of the window, use DisposCWindow with the result of
  25.   -- this function.
  26.   put NewPtr(8) into MyRectPtr
  27.   put rect2 into MyRectPtr@.integerType[1]
  28.   put rect1 into MyRectPtr@.integerType[2]
  29.   put rect4 into MyRectPtr@.integerType[3]
  30.   put rect3 into MyRectPtr@.integerType[4]
  31.   get NewCWindow(NIL, myRectPtr@,WindowName,true,procId,-1,true,nil)
  32.   disposPtr myRectPtr
  33.   return it
  34. end MakeWindow
  35.  
  36.  
  37. function WithinRect h,v,r1,r2,r3,r4
  38.   put h*1 into hh
  39.   put v*1 into vv
  40.   put r1*1 into rr1
  41.   put r2*1 into rr2
  42.   put r3*1 into rr3
  43.   put r4*1 into rr4
  44.   if (hh≥rr1 and vv≥rr2) and (hh≤rr3 and vv≤rr4) then return true
  45.   else return false
  46. end WithinRect
  47.  
  48. function GetBTN h,v
  49.   if WithinRect(h,v,83,0,106,21) then return "9 false"
  50.   if WithinRect(h,v,38,0,61,21) then return "8 false"
  51.   if WithinRect(h,v,60,0,83,21) then return "7 false"
  52.   if WithinRect(h,v,0,42,30,64) then return "6 true"
  53.   if WithinRect(h,v,0,84,30,106) then return "5 true"
  54.   if WithinRect(h,v,0,63,30,85) then return "4 true"
  55.   if WithinRect(h,v,0,21,30,43) then return "3 true"
  56.   if WithinRect(h,v,29,21,349,208) then return "2 false"
  57.   if WithinRect(h,v,0,0,512,342) then return "1 false"
  58.   return 0
  59. end GetBtn
  60.  
  61. function GetRect bNum
  62.   if bNum = "9" then return "83,0,106,21"
  63.   if bNum = "8" then return "38,0,61,21"
  64.   if bNum = "7" then return "60,0,83,21"
  65.   if bNum = "6" then return "0,42,30,64"
  66.   if bNum = "5" then return "0,84,30,106"
  67.   if bNum = "4" then return "0,63,30,85"
  68.   if bNum = "3" then return "0,21,30,43"
  69.   if bNum = "2" then return "29,21,349,208"
  70.   if bNum = "1" then return "0,0,512,342"
  71.   return "THAT BUTTON DOES NOT EXIST"
  72. end GetRect
  73.  
  74. on DrawButton
  75.   put GetResource("PICT",25095) into ButtonPicHandle
  76.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  77.   put  GetResource("PICT",7478) into ButtonPicHandle
  78.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  79.   put  GetResource("PICT",15297) into ButtonPicHandle
  80.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  81.   put  GetResource("PICT",1953) into ButtonPicHandle
  82.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  83.   put  GetResource("PICT",29464) into ButtonPicHandle
  84.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  85.   put  GetResource("PICT",11999) into ButtonPicHandle
  86.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  87.   put  GetResource("PICT",7280) into ButtonPicHandle
  88.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  89.   put  GetResource("PICT",16202) into ButtonPicHandle
  90.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  91.   put  GetResource("PICT",3082) into ButtonPicHandle
  92.   DrawPicture ButtonPicHandle, ButtonPicHandle@@.picFrame
  93. end DrawButton
  94.  
  95. on xMouseDown ml, IsActivate, CmdKeyWasDown, ShiftKeyWasDown, CapsLockKeyWasDown, OptionKeyWasDown, ControlKeyWasDown
  96.   if CmdKeyWasdown then
  97.     put true into CommandKeyWasOrIsDown
  98.     exit xMouseDown
  99.   end if
  100.   put TheMouseLoc.integerType[2] into h
  101.   put TheMouseLoc.integerType[1] into v
  102.   get HandleButton(h,v)
  103.   if it="2 false" then
  104.     DoDraw TheMouseLoc,ShiftKeyWasDown
  105.   else if it="3 true" then put 1 into tool1
  106.   else if it="4 true" then put 3 into tool1
  107.   else if it="5 true" then put 3 into tool1
  108.   else if it="6 true" then put 2 into tool1
  109.   else if it="7 false" then
  110.     if OptionKeyWasDown then PickAColor ShiftKeyWasDown
  111.     else
  112.       put 32767 into Color.integerType[1]
  113.       put 32767 into Color.integerType[2]
  114.       put 32767 into Color.integerType[3]
  115.     end if
  116.   else if it="8 false" then
  117.     if OptionKeyWasDown then PickAColor ShiftKeyWasDown
  118.     else
  119.       put 0 into Color.integerType[1]
  120.       put 0 into Color.integerType[2]
  121.       put 0 into Color.integerType[3]
  122.     end if
  123.   else if it="9 false" then
  124.     if OptionKeyWasDown then PickAColor ShiftKeyWasDown
  125.     else
  126.       put -1 into Color.integerType[1]
  127.       put -1 into Color.integerType[2]
  128.       put -1 into Color.integerType[3]
  129.     end if
  130.   end if
  131. end xMouseDown
  132.  
  133. on xMouseUp TheMouseLoc, IsActivate, CmdKeyWasDown, ShiftKeyWasDown, CapsLockKeyWasDown, OptionKeyWasDown, ControlKeyWasDown
  134. end xMouseUp
  135.  
  136. on xKeyDown TheKey, IsActivate, CmdKeyWasDown, ShiftKeyWasDown, CapsLockKeyWasDown, OptionKeyWasDown, ControlKeyWasDown
  137. end xKeyDown
  138.  
  139. on xKeyUp TheKey, IsActivate, CmdKeyWasDown, ShiftKeyWasDown, CapsLockKeyWasDown, OptionKeyWasDown, ControlKeyWasDown
  140. end xKeyUp
  141.  
  142. on xAutoKey TheKey, IsActivate, CmdKeyWasDown, ShiftKeyWasDown, CapsLockKeyWasDown, OptionKeyWasDown, ControlKeyWasDown
  143. end xAutoKey
  144.  
  145. on xUpdateWindow WindowPtr
  146. end xUpdateWindow
  147.  
  148. on xDiskInserted DriveNumber, ResultCode
  149. end xDiskInserted
  150.  
  151. on xActivate WindowPtr
  152. end xActivate
  153.  
  154. on xAppleEvent p1, p2
  155. end xAppleEvent
  156.  
  157. on xOpertatingSystem
  158. end xOpertatingSystem
  159.  
  160. on xNullEvent
  161. end xNullEvent
  162.  
  163. Function HandleEvent
  164.   get WaitNextEvent(2, MyEventRecord,1000, NIL)
  165.   put MyEventRecord.where into TheMouseLoc
  166.   put MyEventRecord.when into TheTicks
  167.   put MyEventRecord.Message into TheMsg
  168.   put MyEventRecord.modifiers into TheModifiers
  169.   put (BitAnd(TheModifiers,1)≠0) into IsActivate
  170.   put (BitAnd(TheModifiers,128)≠0) into ButtonWasUp
  171.   put (BitAnd(TheModifiers,256)≠0) into CmdKeyWasDown
  172.   put (BitAnd(TheModifiers,512)≠0) into ShiftKeyWasDown
  173.   put (BitAnd(TheModifiers,1024)≠0) into CapsLockKeyWasDown -- alphaLock
  174.   put (BitAnd(TheModifiers,2048)≠0) into OptionKeyWasDown
  175.   put (BitAnd(TheModifiers,4096)≠0) into ControlKeyWasDown
  176.   if it then
  177.     if MyEventRecord.integerType=1 then xMouseDown TheMouseLoc, IsActivate,CmdKeyWasDown,ShiftKeyWasDown,CapsLockKeyWasDown,OptionKeyWasDown,ControlKeyWasDown
  178.     if MyEventRecord.integerType=2 then xMouseUp TheMouseLoc, IsActivate,CmdKeyWasDown,ShiftKeyWasDown,CapsLockKeyWasDown,OptionKeyWasDown,ControlKeyWasDown
  179.     if MyEventRecord.integerType=3 then xKeyDown theMsg.charType[3], IsActivate,CmdKeyWasDown,ShiftKeyWasDown,CapsLockKeyWasDown,OptionKeyWasDown,ControlKeyWasDown
  180.     if MyEventRecord.integerType=4 then xKeyUp theMsg.charType[3], IsActivate,CmdKeyWasDown,ShiftKeyWasDown,CapsLockKeyWasDown,OptionKeyWasDown,ControlKeyWasDown
  181.     if MyEventRecord.integerType=5 then xAutoKey theMsg.charType[3], IsActivate,CmdKeyWasDown,ShiftKeyWasDown,CapsLockKeyWasDown,OptionKeyWasDown,ControlKeyWasDown
  182.     if MyEventRecord.integerType=6 then xUpdateWindow theMsg -- theMsg is ponter to window
  183.     if MyEventRecord.integerType=7 then xDiskInserted LoWord(theMsg),hiWord(theMsg)
  184.     if MyEventRecord.integerType=8 then xActivate theMsg -- pointer to window
  185.     if MyEventRecord.integerType=10 then xAppleEvent theMsg,TheMouseLoc
  186.     if MyEventRecord.integerType=-15 then xOpertatingSystem
  187.     
  188.   else xNullEvent
  189. end HandleEvent
  190.  
  191.  
  192.  
  193.  
  194. on DoDraw TheMouseLoc,ShiftKeyWasDown
  195.   RGBForeColor color
  196.   Set cursor to 2
  197.   repeat while button()
  198.   end repeat
  199.   getMouse new
  200.   put TheMouseLoc into TempRect.longIntType[1]
  201.   put new into TempRect.longIntType[2]
  202.   if ShiftKeyWasDown then -- ha ha ha! Only a line!
  203.     moveTo tempRect.integerType[2],tempRect.integerType[1]
  204.     LineTo tempRect.integerType[4],tempRect.integerType[3]
  205.   else
  206.     if tool1=0 then exit doDraw
  207.     else if Tool1=1 then
  208.       PaintRect TempRect -- Rectangle
  209.       RGBForeColor ColorBorder
  210.       frameRect TempRect -- border
  211.     else if Tool1=2 then
  212.       PaintRoundRect TempRect,15,15 -- Rounded Rectangle
  213.       RGBForeColor ColorBorder
  214.       frameRoundRect TempRect,15,15 -- border
  215.     else if Tool1=3 then
  216.       PaintOval TempRect -- oval
  217.       RGBForeColor ColorBorder
  218.       frameOval TempRect -- border
  219.     end if
  220.   end if
  221.   set cursor to "arrow"
  222. end DoDraw
  223.  
  224. Global APoint:L
  225. on PickAColor ShiftKeyWasDown
  226.   RGBForeColor colorBlack -- No!!! Don't fade out!!!
  227.   -- first save window, for redraw...
  228.   put openPicture(thePort@.portRect) into temp
  229.   copybits thePort@.portbits,theport@.portbits,theport@.portRect,thePort@.portRect,0,nil
  230.   closePicture
  231.   put -1 into APoint.integerType[1]
  232.   put -1 into APoint.integerType[2]
  233.   debug checkpoint
  234.   if ShiftKeyWasDown then
  235.     get GetColor(aPoint,"Pick A Color To Frame With:",ColorBorder,ColorBorder)
  236.   else get GetColor(aPoint,"Pick A Color To Draw With:",color,color)
  237.   drawPicture temp,thePort@.portRect
  238.   killPicture temp
  239. end PickAColor